/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.lxx.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lxx.annotation.Db;
import com.lxx.dao.DictDao;
import com.lxx.entity.Dict;
import com.lxx.entity.Page;
import com.lxx.enums.DbType;
import com.lxx.service.IDictService;

/**
 * 字典Service
 * @author ThinkGem
 * @version 2014-05-16
 */
@Service
@Transactional(readOnly = true)
public class DictService implements IDictService{
	
	@Autowired
	private DictDao dictDao;
	/**
	 * 查询字段类型列表
	 * @return
	 */
	@Db(type=DbType.MASTER)
	public List<String> findTypeList(){
		return dictDao.findTypeList(new Dict());
	}

	@Db(type=DbType.MASTER)
	@Transactional(readOnly = false)
	public void save(Dict dict) {
		if (StringUtils.isBlank(dict.getId())){
			dict.preInsert();
			dictDao.insert(dict);
		}else{
			dict.preUpdate();
			dictDao.update(dict);
		}
		int a = 1/0;
	}

	@Transactional(readOnly = false)
	public void delete(Dict dict) {
		dictDao.delete(dict);
	}

	public List<Dict> findAllList(Dict dict) {
		return dictDao.findAllList(dict);
	}

	@Override
	@Db(type=DbType.SLAVE)
	public Dict get(String id) {
		return dictDao.get(id);
	}

	@Override
	@Db(type=DbType.SLAVE)
	public Dict get(Dict dict) {
		return dictDao.get(dict);
	}
	
	@Override
	@Db(type=DbType.MASTER)
	public Page<Dict> findPage(Page<Dict> page, Dict dict) {
		List<Dict> list = dictDao.findList(dict);
		page.setList(list);
		return page;
	}

	@Override
	@Db(type=DbType.SLAVE)
	public List<Dict> findList(Dict dict) {
		return dictDao.findList(dict);
	}


}
